/**
 * @author LYJ
 * Created by Administrator on 2018/3/7 0007.
 */
function FoodSalesTable($Table) {
    var This = this;
    this.div = $Table;
    this.type = null;
    this.tableBar = null;
    this.toolBar = null;
    this.myToolBar = null;
    this.errorBar = null;
    this.path = "../static/";

    $(function () {
        This.div.html("");
        This.createTool.init();//表工具
        This.createTable.init();//创建数据表
    });

    this.createTool = {
        init: function () {
            this.bar();
            this.element();
            this.event();
        },
        bar: function () {
            var toolbar =
                '<div class="tableTitle">食品销量</div>'+
                '<div class="error"></div>'+
                '<div class="myToolbar"><div class="fClear" style=" clear:both;"></div></div>'+
                '<div class="toolbar btn-group pull-right"  style="margin-right: 10px" ></div>';
            This.div.append(toolbar);
            This.errorBar = This.div.find(".error");
            This.errorBar.hintModal();
            This.toolBar = This.div.find(".toolbar");
            This.myToolBar = This.div.find(".myToolbar");
        },
        element: function () {

        },
        event: function () {
            
        }
    };

    this.createTable = {
        init: function () {
            var tableHtml = '<table style="min-width: 700px"></table>';
            This.div.append(tableHtml);
            This.tableBar = This.div.find("table");

            var table = This.tableBar;
            table.bootstrapTable({
                method: 'post',                      //请求方式（*）
                url: "foodSales/get",         //请求后台的URL（*）
                toolbar: '.toolbar',
                queryParams: this.queryParams,//传递参数（*）
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                contentType: "application/x-www-form-urlencoded",
                showRefresh: true,                  //是否显示刷新按钮
                clickToSelect: true,                //是否启用点击选中行
                uniqueId: "typeid",                     //每一行的唯一标识，一般为主键列
                columns: [
                    {
                        field: 'checkStatus',
                        checkbox: true,
                        valign:"middle"
                    },
                    {
                        width: "5%",
                        align: "center",
                        formatter: function (value, row, index) {
                            var options = table.bootstrapTable('getOptions');
                            return options.pageSize * (options.pageNumber - 1) + index + 1;
                        }
                    },
                    {
                        field: 'picurl',
                        align: "center",
                        valign: "middle",
                        formatter: function (value, row, index) {
                            return "<img src='"+This.path+value+"' width='30px' height='30px'>";
                        }
                    },
                    {
                        title:'名称',
                        field: 'foodname',
                        align: "center",
                        valign: "middle"
                    },
                    {
                        title:'今日销量',
                        field: 'dailySales',
                        align: "center",
                        valign: "middle"
                    },
                    {
                        title:'周销量',
                        field: 'weekSales',
                        align: "center",
                        valign: "middle"
                    },
                    {
                        title:'月销量',
                        field: 'monthlySales',
                        align: "center",
                        valign: "middle"
                    },
                    {
                        title:'总销量',
                        field: 'totalSales',
                        align: "center",
                        valign: "middle"
                    }
                ]
            });
        },
        queryParams: function (params) {
            return {
                // limit: params.limit,   //页面大小
                // offset:params.offset
            };
        },
        operateFormatter: function (value, row, index) {

        },
        operateEvents: {

        }
    }

    this.ajaxTable = {

    };

    var addTool = function (html) {
        This.toolBar.append(html);
    };

    var addMyTool = function (html) {
        $(html).insertBefore(getMyTool("fClear"));
    };

    var getTool = function (name) {
        return This.toolBar.find("."+name);
    };

    var  getMyTool = function (name) {
        return This.myToolBar.find("."+name);
    }
}